package com.itheima.leetcode.od.c.sort;

import java.util.*;
import java.util.stream.Collectors;

/**
 * <h3>找出作弊的人</h3>
 */
public class IdentifyCheatedPerson {
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        int count = in.nextInt();
        List<Employee> all_employee = new ArrayList<>();
        List<int[]> pairs = new ArrayList<>();
        //最大差就是300
        int min_val = 300;

        HashMap<Integer, List<Integer>> score_map = new HashMap<>();
        for (int i = 0; i < count; i++) {
            int a = in.nextInt();
            int b = in.nextInt();
            if (score_map.containsKey(b)) {
                List<Integer> temp = score_map.get(b);
                temp.add(a);
                score_map.put(b, temp);
            } else {
                List<Integer> temp = new ArrayList<>();
                temp.add(a);
                score_map.put(b, temp);
            }
            Employee employee = new Employee(a, b);
            all_employee.add(employee);
        }

        //按照分数
        Collections.sort(all_employee);

        int i = 1;
        while (i < count) {
            Employee curEmployee = all_employee.get(i);
            int curId = curEmployee.id;
            int curScore = curEmployee.score;
            int preScore = all_employee.get(i - 1).score;
            int diff = curScore - preScore;

            if (min_val > diff) {
                min_val = diff;
                pairs = new ArrayList<>();
                for (int j = 0; j < score_map.get(preScore).size(); j++) {
                    if (score_map.get(preScore).get(j) < curId) {
                        pairs.add(new int[]{score_map.get(preScore).get(j), curId});
                    }
                }
            } else if (min_val == diff) {
                for (int j = 0; j < score_map.get(preScore).size(); j++) {
                    if (score_map.get(preScore).get(j) < curId) {
                        pairs.add(new int[]{score_map.get(preScore).get(j), curId});
                    }
                }
            } else {
                min_val = min_val;
            }
            i += 1;
        }

        System.out.println(pairs.stream()
                .sorted((a, b) -> a[0] - b[0])
                .map(ints -> Arrays.stream(ints)
                        .boxed()
                        .map(String::valueOf)
                        .limit(2)
                        .collect(Collectors.joining(" ")))
                .collect(Collectors.joining("\n")));
    }

    public static class Employee implements Comparable<Employee> {
        int id;
        int score;

        public Employee(int id, int score) {
            this.id = id;
            this.score = score;
        }

        //自定义排序
        @Override
        public int compareTo(Employee o) {
            return -o.score + this.score;
        }
    }
}